﻿# coding: utf-8

import wx
import wx.lib.filebrowsebutton as filebrowse

class wxPanelGSGeneral(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, style = wx.NO_BORDER)
            
        sizerWorkDir = self.__CreateUIWorkDirectory()
        sizerResourceDir = self.__CreateUIResourceDirectory()
        
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(sizerWorkDir, 0, wx.EXPAND|wx.ALL, border = 10)
        sizer.Add(sizerResourceDir, 0, wx.EXPAND|wx.ALL, border = 10)
        sizer.AddStretchSpacer()
        self.SetSizer(sizer)
        
    def __CreateUIWorkDirectory(self):
        sbWorkDir = wx.StaticBox(self, -1, TD.WORKING_DIRECTORY)
        sizerWorkDir = wx.StaticBoxSizer(sbWorkDir, wx.VERTICAL)
        self._dbbWorkDir = filebrowse.DirBrowseButton(
            self, -1, changeCallback = self.__OnWorkingDirectoryChanged,
            labelText = u'',
            buttonText = TD.BUTTON_BROWSE,
            startDirectory = GLOBAL_SETTING._workDir)
            
        self._dbbWorkDir.SetValue(GLOBAL_SETTING._workDir)
        
        sizerWorkDir.Add(self._dbbWorkDir, 0, wx.EXPAND|wx.ALL, border = 10)
        return sizerWorkDir
        
    def __CreateUIResourceDirectory(self):
        sbResourceDir = wx.StaticBox(self, -1, TD.RESOURCE_DIRECTORY)
        sizerResourceDir = wx.StaticBoxSizer(sbResourceDir, wx.VERTICAL)
        
        sizerModelDir = self.__CreateUIModelDirectory()
        sizerEffectDir = self.__CreateUIEffectDirectory()
        sizerTextureDir = self.__CreateUITextureDirectory()
        sizerResourceDir.Add(sizerModelDir, 0, wx.EXPAND|wx.ALL, border = 10)
        sizerResourceDir.Add(sizerEffectDir, 0, wx.EXPAND|wx.ALL, border = 10)
        sizerResourceDir.Add(sizerTextureDir, 0, wx.EXPAND|wx.ALL, border = 10)
        
        return sizerResourceDir
        
    def __CreateUIModelDirectory(self):
        static = wx.StaticText(self, -1, TD.MODEL_DIRECTORY)
        self._dbbModelDir = filebrowse.DirBrowseButton(
            self, -1, changeCallback = self.__OnModelDirectoryChanged,
            labelText = u'',
            buttonText = TD.BUTTON_BROWSE,
            startDirectory = GLOBAL_SETTING._workDir + GLOBAL_SETTING._modelDir)
            
        self._dbbModelDir.SetValue(GLOBAL_SETTING._workDir + GLOBAL_SETTING._modelDir)
        
        sizerModelDir = wx.BoxSizer(wx.HORIZONTAL)
        sizerModelDir.Add(static, 0, wx.CENTER, border = 0)
        sizerModelDir.Add(self._dbbModelDir, 1, wx.EXPAND|wx.ALL, border = 0)
        return sizerModelDir
    
    def __CreateUIEffectDirectory(self):
        static = wx.StaticText(self, -1, TD.EFFECT_DIRECTORY)
        self._dbbEffectDir = filebrowse.DirBrowseButton(
            self, -1, changeCallback = self.__OnEffectDirectoryChanged,
            labelText = u'',
            buttonText = TD.BUTTON_BROWSE,
            startDirectory = GLOBAL_SETTING._workDir + GLOBAL_SETTING._effectDir)
        
        self._dbbEffectDir.SetValue(GLOBAL_SETTING._workDir + GLOBAL_SETTING._effectDir)
        
        sizerEffectDir = wx.BoxSizer(wx.HORIZONTAL)
        sizerEffectDir.Add(static, 0, wx.CENTER, border = 0)
        sizerEffectDir.Add(self._dbbEffectDir, 1, wx.EXPAND|wx.ALL, border = 0)
        return sizerEffectDir
        
    def __CreateUITextureDirectory(self):
        static = wx.StaticText(self, -1, TD.TEXTURE_DIRECTORY)
        self._dbbTextureDir = filebrowse.DirBrowseButton(
            self, -1, changeCallback = self.__OnTextureDirectoryChanged,
            labelText = u'',
            buttonText = TD.BUTTON_BROWSE,
            startDirectory = GLOBAL_SETTING._workDir + GLOBAL_SETTING._textureDir)
        
        self._dbbTextureDir.SetValue(GLOBAL_SETTING._workDir + GLOBAL_SETTING._textureDir)
        
        sizerTextureDir = wx.BoxSizer(wx.HORIZONTAL)
        sizerTextureDir.Add(static, 0, wx.CENTER, border = 0)
        sizerTextureDir.Add(self._dbbTextureDir, 1, wx.EXPAND|wx.ALL, border = 0)
        return sizerTextureDir
                            
    def __OnWorkingDirectoryChanged(self, e):
        v = self._dbbWorkDir.GetValue()
        if not v.endswith('\\'):
            v += '\\'
        GLOBAL_SETTING._workDir = v
        
    def __OnModelDirectoryChanged(self, e):
        v = self._dbbModelDir.GetValue()
        if not v.endswith('\\'):
            v += '\\'

        GLOBAL_SETTING._modelDir = REMOVE_ROOT_PATH(v)
       
    def __OnEffectDirectoryChanged(self, e):
        v = self._dbbEffectDir.GetValue()
        if not v.endswith('\\'):
            v += '\\'
            
        GLOBAL_SETTING._effectDir = REMOVE_ROOT_PATH(v)
        
    def __OnTextureDirectoryChanged(self, e):
        v = self._dbbTextureDir.GetValue()
        if not v.endswith('\\'):
            v += '\\'
            
        GLOBAL_SETTING._textureDir = REMOVE_ROOT_PATH(v)        
        